﻿using System;
using DBServer.Selenium.Extenium.Exception;
using Selenium;
using DBServer.Selenium.Extenium.Path;

namespace DBServer.Selenium.Extenium.Fixtures
{
    public class WindowFixture : ExtComponentFixture
    {
        public WindowFixture(ISelenium driver, IPath path)
            :base(driver, path)
        {
        }

        public void Close()
        {
            SafeExec(Path.Eval() + ".close()");
        }

        public WindowFixture RequireVisible()
        {
            var contains = bool.Parse(SafeExec(Path.Eval() + ".isVisible()"));

            if (!contains)
            {
                throw new ExteniumException("Window is not visible");
            }
            return this;
        }

        public WindowFixture RequireClosed()
        {
            var result = SafeExec(Path.Eval());
            if (result != "null")
            {
                throw new ExteniumException("Window is not closed");
            }
            return this;
        }
    }
}
